package 数据结构.章节09._150_JavaListApI;

import java.util.*;

/**
 * @author 挚爱之夕
 * @date 2021/10/9 - 10 - 09 - 21:18
 * @Description: 数据结构.章节09._150_JavaListApI
 * @Version: 1.0
 */
public class APIDemo {
    private static class Student{
        protected int age;
        protected String name;

        public int getAge() {
            return age;
        }

        public Student(int age, String name) {
            this.age = age;
            this.name = name;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "age=" + age +
                    ", name='" + name + '\'' +
                    '}';
        }
    }
    public static void main(String[] args) {
        List<String> list = new LinkedList<>();
        list.add("Dylan");
        list.add("Ron");
        list.add("Harry");
        System.out.println(list);
        Collections.sort(list);
        System.out.println(list);
        List<Student> list1 = new ArrayList<>();
        list1.add(new Student(13,"Dylan"));
        list1.add(new Student(11,"Ron"));
        //添加一个比较器
        Collections.sort(list1,(o1, o2)->{
           return o1.age - o2.age;
        });
        System.out.println(list1);
        System.out.println("--------------------");
        //迭代
        for (int i = 0; i < list1.size(); i++) {
            System.out.println(list1.get(i));
        }
        System.out.println("-------------------");
        for (Student s:list1
             ) {
            System.out.println(s);
        }
        System.out.println("++++++++++++++");
        Iterator<Student> iterator = list1.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
